True if target currently holds no items, false otherwise. The way to know, BEFORE calling stack_pop/stack_peek, whether the value they would give back is a real item or just the empty-container default.
stack_empty(target) -> bool| Name | Type |
|---|---|
target | stack |
bool
true if target currently holds no items, false otherwise. The same answer as stack_length(target) == 0, spelled as its own question.
This is the way to know, BEFORE calling stack_pop/stack_peek, whether the value either would give back is a real item or just the empty-container default - useful anywhere the difference matters (an undo button that should gray itself out once there is nothing left to undo, say).
/// @type {stack<int>}
var history = [];
var nothing_to_undo = stack_empty(history); // true
stack_push(history, 1);
var has_moves = stack_empty(history); // false



Just the vector's empty() - O(1).